<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 16-11-26
 * Time: 下午8:02
 */
namespace app\common\model;

use think\Model;
use think\Db;
abstract class BaseOrder extends Model{
    //缓存配置
    protected $cache_options =  [
        'type'=>'memcached',
        'host'=>'127.0.0.1',
        'port'=>'11211',
        'prefix'=>'water',
        'expire'=>60
    ];
    /**
     * 取单条订单信息
     *
     * @param unknown_type $condition
     * @param array $extend 追加返回那些表的信息,如array('order_common','order_goods','store')
     * @return unknown
     */
    abstract public function getOrderInfo($condition , $fields ,$extend);

    abstract public function getOrderCommonInfo($condition , $field);

    abstract public function getOrderPayInfo($condition);

    /**
     * 取得支付单列表
     *
     * @param unknown_type $condition
     * @param unknown_type $pagesize
     * @param unknown_type $filed
     * @param unknown_type $order
     * @param string $key 以哪个字段作为下标,这里一般指pay_id
     * @return unknown
     */
    abstract public function getOrderPayList($condition, $filed , $order , $page , $pagesize);

    /**
     * 取得订单列表
     * @param unknown $condition
     * @param string $pagesize
     * @param string $field
     * @param string $order
     * @param string $limit
     * @param unknown $extend 追加返回那些表的信息,如array('order_common','order_goods','store')
     * @return Ambigous <multitype:boolean Ambigous <string, mixed> , unknown>
     */
   abstract public function getOrderList($condition, $field , $order , $page , $pagesize);

    /**
     * 取得订单数量
     * @param unknown $condition
     */
    abstract public function getOrderCount($condition);
    /**
     * 取得订单商品表详细信息
     * @param unknown $condition
     * @param string $fields
     * @param string $order
     */
    abstract public function getOrderGoodsInfo($condition , $fields , $order);

    /**
     * 取得订单商品表列表
     * @param unknown $condition
     * @param string $fields
     * @param string $limit
     * @param string $page
     * @param string $order
     * @param string $group
     * @param string $key
     */
    abstract public function getOrderGoodsList($condition , $fields , $order , $page , $pagesize);

    /**
     * 取得订单扩展表列表
     * @param unknown $condition
     * @param string $fields
     * @param string $limit
     */
    abstract public function getOrderCommonList($condition , $fields , $order , $page , $pagesize);

    /**
     * 插入订单支付表信息
     * @param array $data
     * @return int 返回 insert_id
     */
    public function addOrderPay($data){
        return Db::name('shop_order_pay')->insert($data);
    }

    /**
     * 插入订单表信息
     * @param array $data
     * @return int 返回 insert_id
     */
    public function addOrder($data) {
        return Db::name('shop_order')->insert($data);
    }

    /**
     * 插入订单扩展表信息
     * @param array $data
     * @return int 返回 insert_id
     */
    public function addOrderCommon($data) {
        return Db::name('shop_order_common')->insert($data);
    }

    /**
     * 插入订单扩展表信息
     * @param array $data
     * @return int 返回 insert_id
     */
    public function addOrderGoods($data) {
        return Db::name('shop_order_goods')->insertAll($data);
    }

    /**
     * 添加订单日志
     */
    public function addOrderLog($data) {
        $data['log_role'] = str_replace(array('buyer','seller','supplier'),array('买家','商家','供货商'), $data['log_role']);
        $data['log_time'] = TIMESTAMP;
        return Db::name('shop_order_log')->insertAll($data);
    }

    /**
     * 更改订单信息
     *
     * @param unknown_type $data
     * @param unknown_type $condition
     */
    public function editOrder($data,$condition) {
        return Db::name('shop_order')->where($condition)->update($data);
    }

    /**
     * 更改订单信息
     *
     * @param unknown_type $data
     * @param unknown_type $condition
     */
    public function editOrderCommon($data,$condition) {
        return Db::name('shop_order_common')->where($condition)->update($data);
    }

    /**
     * 更改订单支付信息
     *
     * @param unknown_type $data
     * @param unknown_type $condition
     */
    public function editOrderPay($data,$condition) {
        return Db::name('shop_order_pay')->where($condition)->update($data);
    }

    /**
     * 订单操作历史列表
     * @param unknown $order_id
     * @return Ambigous <multitype:, unknown>
     */
    abstract public function getOrderLogList($condition);

    /**
     * 返回是否允许某些操作
     * @param unknown $operate
     * @param unknown $order_info
     */
    abstract public function getOrderOperateState($operate,$order_info);

    /**
     * 联查订单表订单商品表
     *
     * @param array $condition
     * @param string $field
     * @param number $page
     * @param string $order
     * @return array
     */
    abstract public function getOrderAndOrderGoodsList($condition, $field , $order ,$page ,$pagesize );

    /**
     * 订单销售记录 订单状态为20、30、40时
     * @param unknown $condition
     * @param string $field
     * @param number $page
     * @param string $order
     */
    abstract public function getOrderAndOrderGoodsSalesRecordList($condition, $field , $order , $page ,$pagesize);

    /**
     * 买家订单状态操作
     *
     */
    abstract public function memberChangeState($state_type, $order_info, $member_id, $member_name, $extend_msg);

}